package com.lib.common.utils

/**
 * Copyright (C), 2020-2020, 享物说
 * FileName: EncryptUtil
 * Author: keanbin
 * Date: 2020-02-06 09:33
 * Description: 加密工具类
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class EncryptUtil {

    companion object {

        /**
         * 获取MD5字符串
         *
         * @param s String
         * @return MD5 String
         */
        fun getMD5(s: String): String {
            try {
                // Create MD5 Hash
                val digest = java.security.MessageDigest.getInstance("MD5")
                digest.update(s.toByteArray())
                val messageDigest = digest.digest()

                // Create Hex String
                val hexString = StringBuilder()
                for (aMessageDigest in messageDigest)
                    hexString.append(Integer.toHexString(0xFF and aMessageDigest.toInt()))
                return hexString.toString()
            } catch (e: Exception) {
                e.printStackTrace()
            }

            return ""
        }
    }
}